import router from './router'
import { getToken } from './utils/auth'

//定义白名单
const whitePage = ['/login','/']
router.beforeEach((to, from, next) => {
    console.log(to)
    //判断是否有token
    const hasToken = getToken()
    //如果存在token
    if (hasToken) {
        next()
    } else {
        if (whitePage.includes(to.path)) {
            next()
        } else {
            next(`/login?redirect=${to.path}`)
        }
    }
})